<?php $this->load->view('templates/backend/header'); ?>
<h3><?php echo $this->lang->line('getApiSales_list');?></h3>

<?php if (isset($api_update)): ?>
<div class="alert alert-success"><a class="close" paymentAir-dismiss="alert">x</a><strong><?php echo $api_update; ?></strong></div>
<?php endif; ?>
<div class="well">
    <?php echo form_open();?>
        <div class="tab-content">	
            <div class="tab-pane active" id="main">
                <?php
                    echo form_label($this->lang->line('staff'), 'username');
                    echo form_dropdown('username', $data_user, '0','id="username"');
                    echo form_error('username');
                    
                    echo form_label($this->lang->line('airline'), 'airline');
                    echo form_input(array('name' => 'airline', 'id' => 'airline', 'value' => '','readonly' => 'true'));
                    echo form_error('airline');
                ?>
            </div>
        </div>
        <br/>
        <div class="top-button">
                <?php echo form_button(array('id' => 'submit', 'value' => 'Update', 'name' => 'submit', 'type' => 'submit', 'content' => $this->lang->line('save'),'class' => 'btn btn-primary')); ?>
                <a href="<?php echo site_url('auth/getApiSales'); ?>" class="btn"><?php echo $this->lang->line('cancel')?></a>
        </div>
    <?php form_close();?>
    <span id="simple-msg-submit"></span>
</div>

<style>
    .table .new,.notice{
        font-weight: bold;
        color:#D65824;
    }
    .table-bordered{
            border-top:1px solid #ccc;
    }
</style>

<h3><?php echo $this->lang->line('list').' '.$this->lang->line('getApiSales_list');?></h3>
<?php
if(!empty($lists)){
?>
<table class="table table-striped table-bordered dataTable" id="data-table" width="100%" aria-describedby="data-table_info" style="width: 100%;">
    <thead>
        <tr role="row">
            <th width="5%" class="sorting" role="columnheader" tabindex="0" aria-controls="data-table" rowspan="1" colspan="1" aria-label="STT" style="width: 50px;">STT</th>
            <th width="5%" class="sorting_desc" role="columnheader" tabindex="0" aria-controls="data-table" rowspan="1" colspan="1" aria-label="Username" style="width: 280px;"><?php echo $this->lang->line('username');?></th>
            <th width="5%" class="sorting_desc" role="columnheader" tabindex="0" aria-controls="data-table" rowspan="1" colspan="1" aria-label="Username" style="width: 280px;"><?php echo $this->lang->line('menu_role');?></th>
            <th width="5%" class="sorting_desc" role="columnheader" tabindex="0" aria-controls="data-table" rowspan="1" colspan="1" aria-label="Username" style="width: 280px;"><?php echo $this->lang->line('lastupdated');?></th>
        </tr>
    </thead>

    <tbody role="alert" aria-live="polite" aria-relevant="all">
        <?php
            foreach($lists as $key => $value){
                $username       = $this->getApiSales_model->getOwnerFromTblUser($value->user_id);
                $permission     = implode(",", json_decode($value->permission));
                
                echo '<tr>';
                echo '<td>'.++$key.'</td>';
                echo '<td>'.$username[0]->firstname.'</td>';
                echo '<td>'.$permission.'</td>';
                echo '<td>'.date("d-m-Y H:i:s",$value->lastupdated).'</td>';
                echo '</tr>';
            }
        ?>
    </tbody>
</table>
<?php
} else {
    echo "NOT found!!!!";
}
?>
<link rel="stylesheet" href="<?php echo STATIC_URL;?>backend/css/tag_editor/jquery.tag-editor.css">
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="https://code.jquery.com/ui/1.10.2/jquery-ui.min.js"></script>
<script src="<?php echo STATIC_URL;?>backend/js/tag_editor/jquery.caret.min.js"></script>
<script src="<?php echo STATIC_URL;?>backend/js/tag_editor/jquery.tag-editor.js"></script>
<script type="text/javascript">
    
$(document).ready(function(){
    $("#username").on('change',function(){
        if($("#username").val()){
            setTimeout(function () {
                $.ajax(
                    {
                        url : '/auth/getApiSales/getInfo/',
                        data: {user_id:$("#username").val()},
                        type: "POST",
                        beforeSend: function(){
                            
                        },
                        success:function(data) 
                        {
                            $("ul.tag-editor.ui-sortable").remove();
                            if(data){
                                $('#airline').tagEditor({
                                    initialTags: JSON.parse(data),
                                    forceLowercase: false,
                                    placeholder: 'Enter airlines VN, VJ... ...'
                                });
                            } else {
                                $('#airline').tagEditor({
                                    autocomplete: {
                                        delay: 0, // show suggestions immediately
                                        position: { collision: 'flip' }, // automatic menu position up/down
                                        source: ['VN','VJ']
                                    },
                                    forceLowercase: false,
                                    placeholder: 'Enter airlines VN, VJ... ...'
                                });
                            }
                        },
                        error: function() 
                        {
                            alert("error!");
                        }
                    });
            }, 1000);
        }
    });
});
</script>

<?php $this->load->view('templates/backend/footer'); ?>